home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / C / Screens / Sprites.c < prev   
Encoding:
C/C++ Source or Header  |  1997-05-10  |  2.3 KB  |  86 lines

  1. /*
  2. ** Sprite example
  3. ** --------------
  4. ** This example shows you how to set up a 16 colour OCS sprite with a
  5. ** doubled X axis (32 pixels width).  Those with hardware experience will
  6. ** know that it takes 4 sprite banks to do this successfully in OCS, which
  7. ** leaves you with another 4 banks to do with what you will.  You can do
  8. ** this same demo in AGA with just 2 banks used.
  9. ** 
  10. ** The sprite is attached to the mouse, so try moving it around a bit.
  11. **
  12. ** To compile with SAS/C
  13. **  1> sc Sprites.c link startup=LIB:gms.o data=far
  14. **
  15. */
  16.  
  17. #include <proto/games.h>
  18.  
  19. extern struct GMSBase *GMSBase;
  20. ULONG  _XCEXIT = NULL;
  21. APTR   PREFSNAME = DEFAULT;
  22.  
  23. ULONG Palette[] = {
  24.    0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,
  25.    0x000000,0x608080,0x406060,0x304040,0xC0C000,0x908000,0x807000,0x605000,
  26.    0x10C020,0x005000,0xB000B0,0x600060,0xF02000,0x901000,0xB0B0B0,0xF0F0F0,
  27.    0x00B0F0,0x006080,0x506080,0x90B0F0,0xF0F000,0xE0E000,0xB0A000,0x504000
  28. };
  29.  
  30. void main(void)
  31. {
  32.   struct Sprite *Sparkie;
  33.   struct GameScreen *GameScreen;
  34.   APTR  SparkieData;
  35.   UWORD Timer=0;
  36.   ULONG ZBXY=0;
  37.  
  38.   if (SparkieData = SmartLoad("GMS:demos/data/RAW.Sparkie",0,MEM_VIDEO)) {
  39.   
  40.     if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
  41.        GSA_Palette,Palette,
  42.        GSA_AmtColours,32,
  43.        GSA_Planes,1,
  44.        GSA_Attrib,SPRITES|NOSCRBDR,
  45.        TAGEND)) {
  46.   
  47.        if (Sparkie = InitSpriteTags(GameScreen,TAGS_SPRITE,NULL,
  48.           SPA_Data,SparkieData,
  49.           SPA_XCoord,100,
  50.           SPA_YCoord,100,
  51.           SPA_Width,16,
  52.           SPA_Height,21,
  53.           SPA_AmtColours,16,
  54.           SPA_ColStart,16,
  55.           SPA_Planes,2,
  56.           SPA_ScrMode,LORES,
  57.           SPA_Attrib,XLONG,
  58.           TAGEND)) {
  59.  
  60.           UpdateSprite(GameScreen,Sparkie);
  61.           ShowScreen(GameScreen);
  62.   
  63.           InitJoyPorts();
  64.   
  65.           while (!(ZBXY&MB_LMB)) {
  66.   
  67.              if (++Timer&0x1) {
  68.                 if (Sparkie->Frame == 5) Sparkie->Frame = 0;
  69.                 else Sparkie->Frame++;
  70.              }
  71.   
  72.              ZBXY = ReadMouse(JPORT1);
  73.              Sparkie->XPos += GetX(ZBXY);
  74.              Sparkie->YPos += GetY(ZBXY);
  75.              WaitVBL();
  76.              UpdateSprite(GameScreen, Sparkie);
  77.           }
  78.        FreeSprite(Sparkie);
  79.        }
  80.     DeleteScreen(GameScreen);
  81.     }
  82.   FreeMemBlock(SparkieData);
  83.   }
  84. }
  85.  
  86.